﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
}

<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/layui.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>报工列表</title>
    <link href="//unpkg.com/layui@2.9.18/dist/css/layui.css" rel="stylesheet">
</head>
<body>
    <form class="layui-form" margin-top: 20px;>
        <div class="layui-form-item">
             <div class="layui-input-inline">
                    <select id="" lay-filter="" required placeholder="请选择工序名称">
                    </select>
             </div>
            <button type="button" class="layui-btn layui-bg-blue" >查询</button>
            <button type="button" class="layui-btn layui-bg-green" lay-on="test-page-custom">新建</button>
            <button type="button" class="layui-btn layui-bg-blue" onclick="edit()">编辑</button>
            <button type="button" class="layui-btn layui-bg-red" onclick="signingDelete()">删除</button>
            <button type="button" class="layui-btn layui-bg-green">导出</button>
        </div>
    </form>
    <div>
        <table class="layui-table" id="signingTable">
            <thead>
                <tr>
                    <th><input type="checkbox" id="selectAll"></th>
                    <th>工单</th>
                    <th>工序名称</th>
                    <th>产品</th>
                    <th>产品编号</th>
                    <th>产品名称</th>
                    <th>产品规格</th>
                    <th>工序状态</th>
                    <th>生产人员</th>
                    <th>报工数</th>
                    <th>单位</th>
                    <th>良品数</th>
                    <th>不良品数</th>
                    <th>开始时间</th>
                    <th>结束时间</th>
                    <th>报工时长(小时)</th>
                    <th>报工时长(分钟)</th>
                    <th>审批状态</th>
                    <th>审批人</th>
                    <th>报工时间</th>
                    <th>创建时间</th>
                    <th>创建人</th>
                    <th>修改人</th>
                    <th>修改时间</th>
                </tr>
            </thead>
            <tbody>
                </tbody>
        </table>
    </div>


    <script src="//unpkg.com/layui@2.9.18/dist/layui.js"></script>
    <script src="//unpkg.com/jquery/dist/jquery.js"></script>
    <script>
        $(function () {
            getSelect()
        });

        //添加跳转页面
        layui.use(function () {
            var $ = layui.$;
            var layer = layui.layer;
            var util = layui.util;
            var form = layui.form;

            // 全选和反选
            $('#selectAll').click(function () {
                $('.itemCheckbox').prop('checked', $(this).prop('checked'));
                form.render('checkbox');
            });

            // 单项选择时检查是否全选
            $('body').on('click', '.itemCheckbox', function () {
                if ($('.itemCheckbox:checked').length === $('.itemCheckbox').length) {
                    $('#selectAll').prop('checked', true);
                } else {
                    $('#selectAll').prop('checked', false);
                }
                form.render('checkbox');
            });

            // 事件
            util.on('lay-on', {
                'test-page-custom': function () {
                    layer.open({
                        type: 2,
                        area: ['900px', '600px'],
                        shadeClose: true,
                        title: '报工管理（新建）',
                        content: '/SigningWork/SigningWorkAddView',

                    });
                }
            });
        });

        //显示
        function getSelect() {
            $.post({
                url: '@ViewBag.Darius' + "/api/GoldIngot/Handle/SigningSelect",
                data: JSON.stringify({}), // 使用 JSON 格式
                async: false,
                dataType: "json",
                contentType: "application/json",
                success: res => {
                    console.log(res)
                    var content = "";
                    $.each(res.data, function () {
                        content += `<tr>
                                <td><input type="checkbox" class="itemCheckbox" value="${this.signingId}"></td>
                                    <td>${this.workSheetId} </td>
                                    <td>${this.workSheetId}</td>
                                    <td>${this.workSheetId}</td>
                                    <td>${this.workSheetId}</td>
                                    <td>${this.workSheetId}</td>
                                    <td>${this.workSheetId}</td>
                                    <td>${this.processStatus}</td>
                                    <td>${this.produceName}</td>
                                    <td>${this.signingNum}</td>
                                    <td>${this.unitName}</td>
                                    <td>${this.goodNum}</td>
                                    <td>${this.badNum}</td>
                                    <td>${this.dateStart.replace("T", " ").substring(0, 19)}</td>
                                    <td>${this.dateEnd.replace("T", " ").substring(0, 19)}</td>
                                    <td>${this.signingTime}</td>
                                    <td>${this.signingMin}</td>
                                    <td>${this.standard}</td>/* 审批状态 */
                                    <td>${this.actual}</td>/* 审批人 */
                                    <td>${this.pricingType}</td>/* 报工时间 */
                                    <td>${this.createDate}</td>
                                    <td>${this.createId}</td>
                                    <td>${this.updateId}</td>
                                    <td>${this.updateDate}</td>
                        </tr>`
                    });
                    $("tbody").html(content);
                }
            })
        }

        //批量删除
        function signingDelete() {
            var selectedCheckboxes = $(':checkbox:gt(0):checked');

            if (selectedCheckboxes.length === 0) {
                layer.msg('请选择要删除的记录');
                return;
            }

            var ids = "";
            selectedCheckboxes.each(function () {
                ids += $(this).val() + ",";
            })

            ids = ids.substring(0, ids.length - 1);
            console.log(ids)
            $.ajax({
                url: '@ViewBag.Darius'+"/api/GoldIngot/Handle/SigningDelete",
                data: JSON.stringify({ ids: ids }), // 使用 JSON 格式
                async: false,
                type:"Delete",
                dataType: "json",
                contentType: "application/json",
                success: res => {
                    console.log(res)
                    if (res.code === 1) {
                        layer.msg('删除成功');
                        getSelect()
                    } else {
                        layer.msg('删除失败');
                    }
                }
            })
        }

        // 编辑功能
        function edit() {
            let selectedCheckboxes = $(':checkbox:gt(0):checked');
            if (selectedCheckboxes.length !== 1) {
                layer.msg('请选择一条记录进行编辑');
                return;
            }
            let signingId = selectedCheckboxes.val();
            console.log(signingId)
            layer.open({
                type: 2,
                area: ['900px', '600px'],
                shadeClose: true,
                title: '报工管理（编辑）',
                content: `/SigningWork/SigningWorkEditView?id=`+signingId,
            });
        }
    </script>
</body>
</html>